<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>门店客户调拨记录</title>
    <link href="../../rs/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap_tab/css/bootstrap-table.css" rel="stylesheet">
    <link href="../../rs/css/animate.min.css" rel="stylesheet">
    <link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet">
    <?php
      require_once('login.php');
     ?>
    <style>
        .input-daterange{width: 100%;}
        .m-b-xs{
            padding-right: 0px;
            padding-left: 0px;
        }
        .editable-click, a.editable-click, a.editable-click:hover {
            border-bottom: 0px;
        }
        .fixed-table-pagination .page-list{
            display: none;
        }
    </style>

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-content form-inline">

            <div class="col-sm-6 m-b-xs">
                <div class="form-group" id="data_5">

                    <div class="input-daterange input-group" id="datepicker">
                        <span class="input-group-btn">
                            <button id="store" style="height:34px;margin-bottom: 0px;margin-right: 5px;border-radius: 3px;" type="button" class="btn btn-sm"> 打印面单</button>
                        </span>
                        <input style="height:34px" type="text" class="input-sm form-control" name="start" value="" id="start"/>
                        <span style="background: #E5E6E7;" class="input-group-addon">到</span>
                        <input style="height:34px" type="text" class="input-sm form-control" name="end" value="" id="end"/>
                        <span id="search" style="background: #E5E6E7;" class="input-group-addon" style="cursor:pointer">查找</span>
                    </div>
                </div>

            </div>

            <div class="col-sm-4 m-b-xs"></div>

            <div class="col-sm-1 m-b-xs">
                <!-- <div class="input-group" id="key">
                    <input style="height:34px;" type="text" name="gjc" placeholder="请输入关键词" class="input-sm form-control">
          					<span class="input-group-btn">
          						<button id="search" style="height:34px;" type="button" class="btn btn-sm"> 查找
                                  </button>
          					</span>
                </div> -->

            </div>

            <table id="table">
            </table>
            <!-- End Example Card View -->
        </div>
    </div>
</div>
<!-- End Panel Other -->
<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table-export.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/tableExport.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/js/store.min.js"></script>  <!-- 打印面单js -->
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-table-editable.min.js"></script>

<script type="text/javascript">

    var $table = $('#table');

    var sign=URLencode($.cookie('sign'));
//    当天的前一天
//    var rq1=(new Date(new Date()-0 - 1*86400000)).format( 'yyyy-MM-dd')+' 00:00:00';

    var dtn={};
    $(function(){

        var start=(new Date(new Date()-0 - 7*86400000)).format( 'yyyy-MM-dd');
        var end=(new Date()).format( 'yyyy-MM-dd');
        $('#start').val(start);
        $('#end').val(end);
        $('#table').bootstrapTable({
            columns: [
                {
                    field: 'state',
                    checkbox: true
                },
                {
                    field: 'djbh',
                    title: '订单单号',

                },
                {
                    field: 'op_rq',
                    title: '订单时间'
                },
                 {
                    field: 'mc1',
                    title: '门店'
                },
                {
                    field: 'mc2',
                    title: '客户'
                },

                {
                    field: 'djlx',
                    title: '类型'
                }

            ],

            detailView: true,
            advancedSearch:true,
            clickToSelect:true,
            showExport:true,
            singleSelect:true,
            uniqueId: "id",
            onExpandRow: function (index, row, $detail) {
               expandTable($detail,row.djbh);
            },

        });
    });

    //    日期插件js开始
    $("#data_5 .input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };
    //    日期插件js结束



    $("#search").click(function(){
        f_s();
    });

    function  f_s(){
        var rq1=$("input[name='start']").val();
        var rq2=$("input[name='end']").val();
        var key=$("input[name='gjc']").val();
        layer.msg('数据加载中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
        $.ajax({
            type: "post",
            url: G_url+'stino/query/cm/'+rq1+'/'+rq2,
            data:'sign='+sign,
            dataType: "json",
            success: function (aftdata){

                dtn=aftdata;
                $('#table').bootstrapTable('load',dtn.order);
                layer.closeAll();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }
     function expandTable($detail, djbh) {
        buildTable($detail.html('<table></table>').find('table'),djbh);
    }
    function buildTable($el, djbh) {

      $.ajax({
          type: "post",
          url: G_url+'stino/load/'+djbh,
          data:'sign='+sign,
          dataType: "json",
          success: function (result){
            
            $el.bootstrapTable({
                columns: [
                    {
                        field: 'prmc',
                        title: '商品名称'
                    },
                    {
                        field: 'je',
                        title: '金额'
                    },
                    {
                        field: 'sl',
                        title: '数量'
                    },
                    {
                        field: 'si',
                        title: '出/入库',
                        formatter:"siFormatter"
                    },
                    {
                        field: 'bz',
                        title: '备注'
                    }
                ],
                data: result.detail,
                detailView: false
            });
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
          }
      });




    }

    function ft(dt){
        if (dt.length==0) return;
        var jj=JSON.stringify(dtn.footer);
        var jsonobj=eval('('+jj+')');
        return jsonobj[this.field];
    }

    function ftm(dt){
        return "总计";
    }

    $("#store").click(function(){
        var val=$table.bootstrapTable('getSelections');
     
        if(val==""){
            layer.msg("请选择订单",{time:2000});
        }else {

          $.ajax({
              type: "post",
              url: G_url+'stino/load/'+val[0].djbh,
              data:'sign='+sign,
              dataType: "json",
              success: function (result){

                store.set("dy",result);
                window.open("md_cusho.html");
              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {
              }
          });

            
        }
    })
</script>
</body>
</html>
